home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / usr (gcc 1.37 libs) / mac / close.c < prev    next >
C/C++ Source or Header  |  1993-12-08  |  735b  |  41 lines

  1. #include <sys/types.h>
  2. #include <sys/syslimits.h>
  3. #include <fcntl.h>
  4. #include "crtlocal.h"
  5.  
  6. int close(int fd)
  7.     {
  8.     int res = -1;
  9.     short refnum = crt_fd_tab[fd].fd;
  10.     int i;
  11.     mysleep(1);
  12.     if (crt_fd_tab[fd].flags & O_PIPE)
  13.         {
  14.         crt_fd_tab[fd].flags = 0;
  15.         refnum = 0;
  16.         }
  17.     for (i = 0; i < OPEN_MAX; i++)
  18.         if ((i != fd) && (refnum == crt_fd_tab[i].fd)) res = i;
  19.     if ((res == -1) && refnum)
  20.             {
  21.             FCBPBRec pb;
  22.             pb.ioRefNum = refnum;
  23.             pb.ioCompletion = 0;
  24.             pb.ioVRefNum = crt_ioVRefNum;
  25.             PBCloseSync((ParmBlkPtr)&pb);
  26.             res = pb.ioResult;
  27.             }
  28.     else res = refnum;
  29.     crt_fd_tab[fd].fd = 0;
  30.     return res;
  31.     }
  32.  
  33. void closeall(void)
  34.     {
  35.     int i;
  36.     for (i = 0; i < OPEN_MAX; i++)
  37.         {
  38.         if (crt_fd_tab[i].fd) close(crt_fd_tab[i].fd);
  39.         }
  40.     }
  41.